package cn.zcscloud.mall.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

@Data
public class PageRequest<T> {
    private Integer pageSize;//每页的条数
    private Integer pageNum;//当前的页码
    private Integer total;//总条数
    private Integer totalPage;//总页数
    private List<T> list;//数据集合

    public static PageRequest init(IPage page){
        PageRequest<Object> pageRequest = new PageRequest<>();

        pageRequest.setPageSize(Integer.valueOf(Math.toIntExact(page.getSize())));
        // pageRequest.setPageNum(page.getPages());
        pageRequest.setPageNum((int) page.getCurrent());
        pageRequest.setList(page.getRecords());
        pageRequest.setTotalPage((int) page.getPages());
        pageRequest.setTotal((int) page.getTotal());
        return pageRequest;
    }

    public void setData(List<T> data){
        this.list = data;
    }
}
